package com.baseweb.webadmin.core.util;

import java.util.HashMap;
import java.util.Map;

/**
 * @description: 接收分页参数bean
 * @author: xiaoqiang
 * @time: 2017-07-08 16:18
 */
public class RequestPage {
    /**
     * 当前页
     */
    private int curPage = 1;
    /**
     * 每页条数
     */
    private int pageSize = 10;

    /**
     * 排序字段
     */
    private String sort;
    /**
     * 排序顺序
     */
    private String order;

    private int start;

    private int total = 1;

    public int getStart() {
        start = (getCurPage()-1) * getPageSize();
        return start < 0 ? 0 : start;
    }

    public void setStart(int start) {
        this.start = start;
    }

    public int getCurPage() {
        return curPage;
    }

    public void setCurPage(int curPage) {
        this.curPage = curPage;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public String getSort() {
        return sort;
    }

    public void setSort(String sort) {
        this.sort = sort;
    }

    public String getOrder() {
        return order;
    }

    public void setOrder(String order) {
        this.order = order;
    }

    public int getTotal() {
        return total;
    }

    public void setTotal(int total) {
        this.total = total;
    }

    public Map<String, String> getSortAndOrder() {
        Map<String, String> map = new HashMap<String, String>();
        if (this.getSort() == null)
            return null;
        String[] _sort = this.getSort().split(",");
        String[] _order = this.getOrder().split(",");
        for (int i = 0; i < _sort.length; i++) {
            map.put(_sort[i], _order[i]);
        }
        return map;
    }
}
